<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
<#include "/jeecms_sys/head.html"/>
<script src="${base}/thirdparty/swfupload/swfupload.js" type="text/javascript"></script>
<script src="${base}/thirdparty/swfupload/swfupload.queue.js" type="text/javascript"></script>
<script src="${base}/thirdparty/swfupload/fileprogress.js" type="text/javascript"></script>
<script src="${base}/thirdparty/swfupload/handlers.js" type="text/javascript"></script>
<link href="${base}/thirdparty/swfupload/process.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
function getTableForm() {
	return document.getElementById("tableForm");
}
function optDelete() {
	if(Pn.checkedCount('ids')<=0) {
		$.alert("<@s.m 'global.prompt'/>","<@s.m 'error.checkRecord'/>");
		return;
	}
	$.confirm(doDelete,"<@s.m 'global.confirm'/>","<@s.m 'global.confirm.delete'/>");
}
function doDelete(){
	var f = getTableForm();
	f.action="o_delete.do";
	f.submit();
}

function doDeleteSingle(root,name){
	var f = getTableForm();
	f.action="o_delete_single.do?root="+root+"&name="+name+"";
	f.submit();
}

function doDelFreeFiles(){
	var f = getTableForm();
	f.action="o_delfreefiles.do";
	f.submit();
}

function delFreeFiles() {
	$.confirm(doDelFreeFiles);
}

function flagFiles() {
	var f = getTableForm();
	f.action="o_flag_files.do";
	f.submit();
}

var swfu;
window.onload=function() {
	var uploadUrl = "o_swfupload.do";
	//在firefox、chrome下，上传不能保留登录信息，所以必须加上jsessionid。
	var jsessionid = $.cookie("JSESSIONID");
	if(jsessionid) {
		uploadUrl += ";jsessionid="+jsessionid;
	}
	swfu=new SWFUpload({
		upload_url : uploadUrl,
		flash_url : "${base}/thirdparty/swfupload/swfupload.swf",
		file_size_limit : "1000 MB",
		post_params: {"root" : "${root}"},
		file_types : "*.*",
		file_types_description : "All Files",
		file_queue_limit : 0,
		custom_settings : {
			progressTarget : "fsUploadProgress",
			cancelButtonId : "btnCancel"
		},
		debug: false,
		
		button_image_url : "${base}/res/common/img/theme/menu_search.jpg",
		button_placeholder_id : "spanButtonPlaceHolder",
		button_text: "<span class='btnText'><@s.m "resource.upload"/></span>",
		button_width: 52,
		button_height: 19,
		button_text_top_padding: 2,
		button_text_left_padding: 0,
		button_text_style: '.btnText{color:#666666;}',
		
		file_queued_handler : fileQueued,
		file_queue_error_handler : fileQueueError,
		file_dialog_complete_handler : fileDialogComplete,
		upload_start_handler : uploadStart,
		upload_progress_handler : uploadProgress,
		upload_error_handler : uploadError,
		upload_success_handler : uploadSuccess,
		upload_complete_handler : uploadComplete,
		queue_complete_handler : queueComplete2
	});
};
function queueComplete2(numFilesUploaded) {
	//刷新页面
	location.href="v_list.do?root=${root}";
}
var max=300;
function showImage(a) {
	var img = $("<img src='"+ a.href +"' style='border:1px solid #ccc;'/>");
	var imgDiv = $("#sd").append(img);	
	imgDiv.show();
	
	var	width = img.attr("width");
	var	height = img.attr("height");
	if(width>=height&&width>max) {
		height = height*max/width;
		width = max;
	} else if(height>=width||height>max) {
		width = width*max/height;
		height = max;
	}
	var offset = $(a).offset();
	imgDiv.css("left",offset.left+$(a).outerWidth()+3);	
	var buttom = $(window).height()+$(document).scrollTop()-max-offset.top;
	if(buttom<0) {
		imgDiv.css("top",offset.top+buttom-3);
	} else {
		imgDiv.css("top",offset.top-3);
	}
	img.width(width);
	img.height(height);
}
function hideImage(a) {
	$("#sd").empty().hide();
}
</script>
</head>
<body>
<div id="sd" style="display:none;position:absolute;height:300px;width:300px"></div>
<div class="box-positon">
	<div class="rpos"><@s.m "global.position"/>: <@s.m "cms.function.attachment"/> - <@s.m "global.list"/></div>
	<div class="clear"></div>
</div>
<div class="body-box">

<form method="post" enctype="multipart/form-data"  action="v_list.do">
<input type="hidden" name="root" value="${root}"/>
<table border="0" style="padding-top:3px">
<tr>
	<td><@s.m "resource.currentDir"/>: ${root}</td>
	<@cms_perm url="/file/o_swfupload.do">
	<td width="70" align="center"><span id="spanButtonPlaceHolder"></span></td>
	<td><input class="cancel" id="btnCancel" type="button" value="<@s.m "global.cancel"/>" onclick="swfu.cancelQueue();" disabled="disabled" /></td>
	</@cms_perm>
	<@cms_perm url="/file/o_list.do">
	<td>
		<input name="valid" type="radio" value="1" <#if valid??><#if valid>checked="checked"</#if></#if>/><@s.m "cms.attachment.valid.true"/>
		<input name="valid" type="radio" value="0" <#if valid??><#if !valid>checked="checked"</#if></#if>/><@s.m "cms.attachment.valid.false"/>
		<input class="query" type="submit" value="<@s.m "global.query"/>" > 
	</td>
	</@cms_perm>
	<@cms_perm url="/file/o_delfreefiles.do">
	<td><input type="button" class="delete-all-failure-attachment" value="<@s.m "cms.attachment.delete.all.failure"/>" onclick="delFreeFiles()" /> </td>
	</@cms_perm>
	<@cms_perm url="/file/o_flag_files.do">
	<td><input type="button" class="flag-attachment" value="<@s.m "cms.attachment.flag"/>" onclick="flagFiles()" /> </td>
	</@cms_perm>
</tr>
<tr><td colspan="4"><div id="fsUploadProgress"></div></td></tr>
</table>
</form>
<form id="tableForm" method="post">
<input type="hidden" name="root" value="${root}"/>
<@p.table value=list;resource,i,has_next><#rt/>
	<@p.column title="<input type='checkbox' onclick='Pn.checkbox(\"names\",this.checked)'/>" width="25" align="center">
		<input type="checkbox" name="names" value="${resource.name}" /><#t/>
	</@p.column><#t/>
	<@p.column title=" " width="25" align="center"><img src="${base}/res/common/img/file/${resource.ico}.gif"/></@p.column><#t/>
	<@p.column code="resource.filename" align="center">
		<#if resource.directory>
		<a href="v_list.do?root=${resource.name}">${resource.filename}</a>
		<#else>
		<a href="${base+resource.name}"<#if resource.image> onmouseover="showImage(this)" onmouseout="hideImage(this)"</#if> target="_blank">${resource.filename}</a>
		</#if>
	</@p.column><#t/>
	<@p.column code="resource.size" align="center">${resource.size} KB</@p.column><#t/>
	<@p.column code="cms.attachment.valid" align="center"><#if resource.valid><@s.m "cms.attachment.valid.true"/><#else><@s.m "cms.attachment.valid.false"/></#if> </@p.column><#t/>
	<@p.column code="resource.lastModified" align="center">${resource.lastModifiedDate?string('yyyy-MM-dd HH:mm:ss')}</@p.column><#t/>
	<@p.column code="global.operate" align="center">
		<@cms_perm url="/resource/o_delete_single.do">
		<a href="o_delete_single.do?root=${root?url}&name=${resource.name?url}" onclick="if(!$.confirmToUrl(this.href)) {return false;}"  class="pn-opt"><@s.m "global.delete"/></a><#t/>
		</@cms_perm>
	</@p.column><#t/>
</@p.table>
<div style="background:url(${base}/res/common/img/theme/boxTitleBG.jpg) repeat-x; height:20px; overflow:hidden;">
	<@cms_perm url="/file/o_delete.do">
	<input type="button" value="<@s.m "global.delete"/>" onclick="optDelete();" class="del-button"/ style="float:left; border-right:1px solid #ffffff;">
	</@cms_perm>
</div>
</form>
</div>
<#include "/common/alert_message.html"/>
</body>
</html>